﻿using Assignment_3.Classes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Assignment_3.Feature___Housekeeping
{
    public partial class AddHousekeeping : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["username"] == null || Session["usertype"] == null)
            {
                Response.Redirect("~/Feature - Users/Login.aspx");
            }

            CalendarExtender1.StartDate = DateTime.Now;
            CalendarExtender1.EndDate = DateTime.Now.AddMonths(1);
            tbxDate.Attributes.Add("ReadOnly", "true");
        }

        protected void tbnCreate_Click(object sender, EventArgs e)
        {
            int roomID = Convert.ToInt32(tbxRoom.Text);
            int staffID = Convert.ToInt32(tbxStaff.Text);

            if (DatabaseManager.compareRoomID(roomID) == false && DatabaseManager.compareStaffID(staffID) == false)
            {
                lblRoom.Text = "There is no Room with that ID!";
                lblStaff.Text = "There is no Staff with that ID!";
            }


            else if (DatabaseManager.compareStaffID(staffID) == false)
            {
                lblStaff.Text = "There is no Staff with that ID!";
                lblRoom.Text = " ";
            }

            else if (DatabaseManager.compareStaffDuty(staffID) == false)
            {
                lblStaff.Text = "This staff is not on room duty!";
                lblRoom.Text = " ";
            }

            else if (DatabaseManager.compareRoomID(roomID) == false)
            {
                lblRoom.Text = "There is no Room with that ID!";
                lblStaff.Text = " ";
            }

            else if (DatabaseManager.compareRoomStatus(roomID) == false)
            {
                lblRoom.Text = "This room's status is not on Vacant & Cleaning!";
                lblStaff.Text = " ";
            }

            else
            {
                lblRoom.Text = " ";
                lblStaff.Text = " ";

                HouseKeeping schedule = new HouseKeeping();
                schedule.StaffID = Convert.ToInt32(tbxStaff.Text);
                schedule.RoomID = Convert.ToInt32(tbxRoom.Text);
                schedule.Date = Convert.ToDateTime(tbxDate.Text);
                schedule.Progress = tbxProgress.Text;

                if (DatabaseManager.compareSchedule(Convert.ToInt32(tbxRoom.Text), tbxProgress.Text) == true)
                {
                    lblStatus.Text = "There is already a schedule created for these datas!";
                }
                else
                {
                    if (DatabaseManager.InsertHouseKeeping(schedule) == 1)
                    {
                        lblStatus.Text = "Schedule is successfully created!";
                    }

                    else
                    {
                        lblStatus.Text = "Schedule is NOT created successfully. Please check again!";
                    }
                }
            }
        }
    }
}